home *** CD-ROM | disk | FTP | other *** search
- /* Standard C Include files */
- /* #include "CType.h" */
- /* #include "ErrNo.h" */
- /* #include "FCntl.h" */
- /* #include "IOCtl.h" */
- /* #include "Math.h" */
- /* #include "SetJmp.h" */
- /* #include "Signal.h" */
- /* #include "StdIO.h" */
- /* #include "String.h" */
-
- /* Primary Interface Files */
- #include "Types.h"
- #include "Resources.h"
- #include "Quickdraw.h"
- #include "Windows.h"
- /* #include "OSUtils.h" */
-
- /* Commonly Included files */
- /* #include "ToolUtils.h" */
- #include "TextEdit.h"
- /* #include "Controls.h" */
-
- /* Other Interface files */
- /* #include "AppleTalk.h" */
- /* #include "CursorCtl.h" */
- /* #include "Desk.h" */
- /* #include "DeskBus.h" */
- /* #include "Devices.h" */
- /* #include "Dialogs.h" */
- /* #include "DiskInit.h" */
- /* #include "Disks.h" */
- /* #include "ErrMgr.h" */
- #include "Errors.h"
- /* #include "Events.h" */
- #include "Files.h"
- /* #include "Fonts.h" */
- /* #include "Graf3D.h" */
- /* #include "Lists.h" */
- #include "Memory.h"
- /* #include "Menus.h" */
- #include "Packages.h"
- /* #include "Palette.h" */
- /* #include "Perf.h" */
- /* #include "Picker.h" */
- /* #include "Printing.h" */
- /* #include "Retrace.h" */
- /* #include "ROMDefs.h" */
- /* #include "SANE.h" */
- #include "Scrap.h"
- /* #include "Script.h" */
- /* #include "SCSI.h" */
- /* #include "SegLoad.h" */
- /* #include "Serial.h" */
- /* #include "Slots.h" */
- /* #include "Sound.h" */
- /* #include "Start.h" */
- /* #include "Strings.h" */
- /* #include "Time.h" */
- /* #include "Traps.h" */
- /* #include "Values.h" */
- /* #include "VarArgs.h" */
- /* #include "Video.h" */
-
- /* Application-specific Include files */
- #include "::TiffLibrary:TIFFLib.h"
- #include "sample.h"
- #include "messages.h"
-
- /*
- * Definitions and Declarations
- */
-
- Point where = {34,80};
- StatString(putPrompt, "Save current document as:");
- StatString(getPrompt, "Save current document as:");
- StatString(untitled, "Untitled");
- static Int16 refNum = -1; /* currently opened file's refNum */
- Str63 currentFName = {0,""};
- SFReply reply;
-
- #define NUMTYPES 2 /* number of file types for SFGETFILE */
- SFTypeList MyTypeList = { /* types of files to open */
- 'TIFF',
- 'SPTG'
- };
-
- void DoOpen(myBitMapPtr)
- BitMap *myBitMapPtr;
- {
- WindowPtr theActiveWindow;
-
- if (refNum > 0) {
- ErrorMessage(FILEOPEN);
- return;
- }
- SFGETFILE(where, &getPrompt, nil, (Int16)NUMTYPES, MyTypeList, nil, &reply);
- if (reply.good == false)
- return;
- /* Set current file name to that just selected */
- currentFName = *((Str63 *)(&(reply.fName)));
- if ((FSOPEN(¤tFName, reply.vRefNum, &refNum)) != noErr) {
- ErrorMessage(BADOPEN);
- refNum = -1;
- return;
- }
- if (ReadTiff(refNum, myBitMapPtr)) {
- theActiveWindow = FrontWindow();
- SETWTITLE(theActiveWindow, ¤tFName);
- }
- else {
- DoClose();
- ClearImage(myBitMapPtr);
- }
- }
-
- void DoClose()
- {
- if (refNum >= 0) { /* no file open */
- if (FSClose(refNum) != noErr) {
- ErrorMessage(BADCLOSE);
- return;
- }
- if (FLUSHVOL(nil, reply.vRefNum) != noErr) {
- ErrorMessage(BADFLUSHVOL);
- return;
- }
- refNum = -1; /* -1 means no file open */
- currentFName.length = 0;
- SETWTITLE(FrontWindow(), &untitled);
- }
- }
-
- void DoSave(MyBitMapPtr)
- BitMap *MyBitMapPtr;
- {
- if (refNum < 0) { /* No currently open file */
- DoSaveAs(MyBitMapPtr);
- }
- else {
- /* truncate file to zero length */
- if ((SetEOF(refNum, 0L)) != noErr) {
- ErrorMessage(BADSETEOF);
- return;
- }
- WriteTiff(refNum, MyBitMapPtr);
- }
- }
-
- void DoSaveAs(myBitMapPtr)
- BitMap *myBitMapPtr;
- {
- WindowPtr theActiveWindow;
- OSErr error;
-
- SFPUTFILE(where, &putPrompt, ¤tFName, nil, &reply);
- if (reply.good == false)
- return;
- if (refNum >= 0) /* If there was a previous file open, close it */
- DoClose();
- /* Set current file name to that just selected */
- currentFName = *((Str63 *)(&(reply.fName)));
- error = FSDELETE(¤tFName, reply.vRefNum);
- if (error != fnfErr && error != noErr) {
- ErrorMessage(BADDELETE);
- return;
- }
- if ((CREATE(¤tFName, reply.vRefNum, CREATOR, FILETYPE)) != noErr) {
- ErrorMessage(BADCREATE);
- return;
- }
- if ((FSOPEN(¤tFName, reply.vRefNum, &refNum)) != noErr) {
- ErrorMessage(BADOPEN);
- refNum = -1;
- return;
- }
- theActiveWindow = FrontWindow();
- SETWTITLE(theActiveWindow, ¤tFName);
-
- WriteTiff(refNum, myBitMapPtr);
- }
-
- void DoQuitCleanUp(myBitMapPtr)
- BitMap *myBitMapPtr;
- {
- DoClose();
- ClearImage(myBitMapPtr);
- }